package com.borrowed.book.book.controller;

import com.borrowed.book.book.domain.AddEvaluteInDto;
import com.borrowed.book.book.domain.SOrderEvalute;
import com.borrowed.book.book.domain.SelectEvaluteInDto;
import com.borrowed.book.book.service.EvaluteService;
import com.borrowed.book.system.controller.BaseController;
import com.borrowed.book.system.domain.AjaxResult;
import com.borrowed.book.system.domain.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "评论管理")
@RequestMapping("/api/evalute")
public class EvaluteController extends BaseController {
    @Autowired
    private EvaluteService evaluteService;


    @ApiOperation(value = "添加评论",httpMethod = "POST")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addEvalute(@RequestBody AddEvaluteInDto param){
        AjaxResult result;
        try{
            evaluteService.addOrderEvalute(param);
            result=AjaxResult.sucess();
        }catch (Exception e){
            e.printStackTrace();
            result=AjaxResult.error(e.getMessage());
        }
        return result;
    }


    @ApiOperation(value = "评论一览查询",httpMethod = "GET")
    @GetMapping("/select")
    @ResponseBody
    @Transactional
    public TableDataInfo getEvalute(SelectEvaluteInDto param){
        startPage();
        List<SOrderEvalute> data=evaluteService.selectOrderEvalute(param);
        return getDataTable(data);
    }
}
